

cd "../replication-package"

/*
	This do-file runs main models 
	
*/

use "data/CPS_state_FB_ELDCH_analytic.dta", clear 
keep if fb_sample_marrcohab==1 


**# ----- Step 0. Standardize state-level indicators & generate main sexism ----- *
local varlist trcwagegap1865_a lfrategap_1865 mf60ratio_wagetrc pct_maleleg  evanpro_dum_m genroleatt_main abany_main  ///
			  femmar1824_cps badum_cps median_cps nhblack_d_cps hispan_d_cps nhother_d_cps 
foreach var of local varlist {
	egen z_`var' = std(`var')
} 

// using 
// 1) gender wage gap
// 2) gender LFP gap 
// 3) occupational pay gap
// 4) % male legislators 
// 5) % Evangelical Protestants 
// 6) Gender role attitude 
// 7) abortion attitude 
// where 1), 2), and 3) are all using population aged 18-65 
alpha z_trcwagegap1865_a z_lfrategap_1865 z_mf60ratio_wagetrc z_pct_maleleg z_evanpro_dum_m z_genroleatt_main z_abany_main, item gen(sexism_main)
sum sexism_main, det


**# ----- Table 1. Descriptive statistics by FB status ----- *
bys cpsidpf (l_year): gen her_share_change = her_share - her_share[_n-1]

// for now, generate both logged and raw earnings 
gen ln_her_earnings = ln(her_earnings + 0.1)
gen ln_his_earnings = ln(his_earnings + 0.1)

foreach g in her his {
	bys cpsidpf (l_year): gen `g'_earnings_change = `g'_earnings - `g'_earnings[_n-1]
	bys cpsidpf (l_year): gen ln_`g'_earnings_change = ln_`g'_earnings - ln_`g'_earnings[_n-1]
}

bys firstbirth l_year: sum her_share her_share_change
bys firstbirth l_year: sum *her_earnings*
bys firstbirth l_year: sum *his_earnings*


**# ----- Table 2. Descriptive statistics of state-level measures ----- *
sum sexism_main if l_year==1 
sum trcwagegap1865_a lfrategap_1865 mf60ratio_wagetrc pct_maleleg evanpro_dum_m genroleatt_main abany_main median_cps nhblack_d_cps hispan_d_cps nhother_d_cps if l_year==1 


**# ----- Figure 2. Descriptive figures of our sexism measure ----- *
// for Panel A
preserve 
keep if l_year==1 
collapse (mean) m_sexism = sexism_main ///
		 (sem) se_sexism = sexism_main, by(state_a)
save "data/results/sexism_by_state.dta", replace 
restore 


// for Panel B
preserve 
keep if l_year==1 
	collapse (mean) m_sexism = sexism_main ///
			 (sd)  sd_sexism = sexism_main ///
			 (mean) m_wagegap  = trcwagegap1865_a ///
			 (sd)  sd_wagegap = trcwagegap1865_a ///
			 (mean) m_lfpgap  = lfrategap_1865 ///
			 (sd)  sd_lfpgap = lfrategap_1865 ///
			 (mean) m_paygap  = mf60ratio_wagetrc ///
			 (sd)  sd_paygap = mf60ratio_wagetrc ///
			 (mean) m_maleleg  = pct_maleleg ///
			 (sd)  sd_maleleg = pct_maleleg ///
			 (mean) m_evanpro  = evanpro_dum_m ///
			 (sd)  sd_evanpro = evanpro_dum_m ///
			 (mean) m_genrole  = genroleatt_main ///
			 (sd)  sd_genrole = genroleatt_main ///
			 (mean) m_abany  = abany_main ///
		     (sd)  sd_abany = abany_main, by(state_a year)

save "data/results/state_context_by_year.dta", replace 
restore 


**# ----- Table 3, Figure 3, Figure 4. Main results for her share and her and his (logged) earnings ----- *
est clear 

xtreg her_share i.firstbir_fe##(c.sexism_main ib1.decade c.z_median_cps c.z_nhblack_d_cps c.z_hispan_d_cps c.z_nhother_d_cps), fe vce(cluster state_a)
est store m_share 

qui margins, at(sexism_main = (-1.5 (0.1) 1.5) firstbir_fe = (1)) saving("data/results/mgp_sexism_her_share.dta", replace)

foreach g in her his {
	xtreg ln_`g'_earnings i.firstbir_fe##(c.sexism_main ib1.decade c.z_median_cps c.z_nhblack_d_cps c.z_hispan_d_cps c.z_nhother_d_cps), fe vce(cluster state_a)
	est store m_`g'
	
	qui margins, at(sexism_main = (-1.5 (0.1) 1.5) firstbir_fe = (1)) saving("data/results/mgp_sexism_`g'_earnings.dta", replace)

}
esttab m_* using "tables/table3.csv", se r2 b(3) compress label star ( + 0.1 * 0.05 ** 0.01 *** 0.001) noomit replace



**# ----- Figure 5. Difference in effects by subgroup ----- *
gen MIS4_age30plus = MIS4_herage >= 30 

// By her NH white or not 
xtreg her_share i.firstbir_fe##MIS4_herwht##(c.sexism_main) ///
				i.firstbir_fe##(ib1.decade c.z_median_cps c.z_nhblack_d_cps c.z_hispan_d_cps c.z_nhother_d_cps), fe vce(cluster state_a)
margins firstbir_fe#MIS4_herwht, dydx(sexism_main)
mat P = (r(table))'
mat F1 = P[3..4 , 1..2]
mat F2 = P[3..4 , 5..6]
mat WHT = F1, F2
mat rownames WHT = nowh wht

// By her BA or not 
xtreg her_share i.firstbir_fe##MIS4_herba##(c.sexism_main) ///
				i.firstbir_fe##(ib1.decade c.z_median_cps c.z_nhblack_d_cps c.z_hispan_d_cps c.z_nhother_d_cps), fe vce(cluster state_a)
margins firstbir_fe#MIS4_herba, dydx(sexism_main)
mat P = (r(table))'
mat F1 = P[3..4 , 1..2]
mat F2 = P[3..4 , 5..6]
mat COL = F1, F2
mat rownames COL = noba yba

// By age at MIS4 
xtreg her_share i.firstbir_fe##MIS4_age30plus##(c.sexism_main) ///
				i.firstbir_fe##(ib1.decade  c.z_median_cps c.z_nhblack_d_cps c.z_hispan_d_cps c.z_nhother_d_cps), fe vce(cluster state_a)
margins firstbir_fe#MIS4_age30plus, dydx(sexism_main)
mat P = (r(table))'
mat F1 = P[3..4 , 1..2]
mat F2 = P[3..4 , 5..6]
mat AFB = F1, F2
mat rownames AFB = b30 a30

// By decade 
xtreg her_share i.firstbir_fe##ib1.decade##(c.sexism_main) ///
				i.firstbir_fe##(c.z_median_cps c.z_nhblack_d_cps c.z_hispan_d_cps c.z_nhother_d_cps), fe vce(cluster state_a)
margins firstbir_fe#decade, dydx(sexism_main)
mat P = (r(table))'
mat F1 = P[5..8 , 1..2]
mat F2 = P[5..8 , 5..6]
mat DC = F1, F2
mat rownames DC = d1980 d1990 d2000 d2010

mat WCA = WHT\COL\AFB\DC 
mat colnames WCA = b se lb ub
preserve 
clear 
svmat WCA, names(col)
save "data/results/threeway_ame_sexism.dta", replace 
restore  



**# ----- Table 4. Eldest child's age ----- #**
use "data/CPS_state_FB_ELDCH_analytic.dta", clear
keep if eldch_sample_marrcohab==1 & post_pandemic_flag==0

local varlist trcwagegap1865_a lfrategap_1865 mf60ratio_wagetrc pct_maleleg  evanpro_dum_m genroleatt_main abany_main  ///
			  femmar1824_cps badum_cps median_cps nhblack_d_cps hispan_d_cps nhother_d_cps 
foreach var of local varlist {
	egen z_`var' = std(`var')
} 

alpha z_trcwagegap1865_a z_lfrategap_1865 z_mf60ratio_wagetrc z_pct_maleleg z_evanpro_dum_m z_genroleatt_main z_abany_main, item gen(sexism_main)

xtreg her_share ib0.eldch_cat##(c.sexism_main ib1.decade c.z_median_cps c.z_nhblack_d_cps c.z_hispan_d_cps c.z_nhother_d_cps), fe vce(cluster state_a)
est store m_eldch

esttab m_eldch using "tables/table4.csv", se r2 b(3) compress label star ( + 0.1 * 0.05 ** 0.01 *** 0.001) noomit replace






